package com.zixun.fragment;


import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.zixun.Models.Message;
import com.zixun.Models.MessageItem;
import com.zixun.R;
import com.zixun.activity.DoctorDetailActivity;
import com.zixun.activity.HomeFragmentDetailActivity;
import com.zixun.adapter.GrowUpAdapter;
import com.zixun.db.DatabaseUtil;
import com.zixun.db.MyHelper;

import java.util.ArrayList;
import java.util.List;

/**
 * 作者：郭郭
 * 成长发展
 */

public class GrowUpFragment extends Fragment {

    private Context context;
    private RecyclerView rlv_content;
    private DatabaseUtil mUtil;
    private List<Message> list = null;


    public GrowUpFragment(Context context) {
        this.context = context;
        InitData(context);
    }

    @Nullable
    @Override
    public View onCreateView(final LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_grow_up, container, false);

        rlv_content = (RecyclerView) view.findViewById(R.id.rlv_content);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
        rlv_content.setLayoutManager(linearLayoutManager);

        GrowUpAdapter adapter = new GrowUpAdapter(getContext(), list);
        adapter.setOnItemClickListener(new GrowUpAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(int position, Message data) {
                //  Toast.makeText(getContext(),"position"+position,Toast.LENGTH_LONG).show();
                Intent intent = new Intent(getActivity(), HomeFragmentDetailActivity.class);
                intent.putExtra("title", data.getTitle());
                intent.putExtra("description", data.getDescription());
                intent.putExtra("type", MyHelper.GROWUP_NAME);
                startActivity(intent);
            }
        });
        rlv_content.setAdapter(adapter);
        return view;
    }

    private void InitData(Context context) {
        mUtil = new DatabaseUtil(context);
        list = mUtil.queryAll5(MyHelper.GROWUP_NAME);
    }
}
